package com.yantong.controller.api;

import com.yantong.annotation.Auth;
import com.yantong.controller.BaseController;
import com.yantong.pojo.Bank;
import com.yantong.pojo.BankBranch;
import com.yantong.pojo.MemberCard;
import com.yantong.result.ResultVo;
import com.yantong.service.BankService;
import com.yantong.service.CardService;
import com.yantong.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author: juzi
 * @date: 2021/10/25
 * @time: 16:12
 */
@ApiIgnore
@Controller
@RequestMapping("/wxapi/bank")
public class ApiBankController extends BaseController {


    @Autowired
    private BankService bankService;
    @Autowired
    private CardService cardService;


    /**
     * 添加银行卡
     */
    @RequestMapping("/addcard")
    @ResponseBody
    @Auth
    public ResultVo addBankCard(MemberCard card) {
        int result = (card.getCdId() != null) ? cardService.updateCard(card) : cardService.saveCard(card);
        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", result);
        return resultVo;
    }

    /**
     * 银行卡列表
     */
    @RequestMapping("/listcard")
    @ResponseBody
    @Auth
    public ResultVo getBankCards(Long memberId, int offset, int limit) {
        PageUtils<MemberCard> cards = cardService.getMemberCards(memberId, offset, limit);
        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", cards);
        return resultVo;
    }


    /**
     * 我的银行卡
     * @param offset
     * @param limit
     * @return
     */
    @RequestMapping("/listtrunk")
    @ResponseBody
    @Auth
    public ResultVo getListTrunk(int offset, int limit) {
        PageUtils<Bank> cards = bankService.getListTrunk(offset - 1, limit);
        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", cards);
        return resultVo;
    }

    /**
     * 支付列表接口
     * @param tbCode
     * @param offset
     * @param limit
     * @return
     */
    @RequestMapping("/listbranch")
    @ResponseBody
    @Auth
    public ResultVo getListBranch(String tbCode, int offset, int limit) {
        PageUtils<BankBranch> cards = bankService.getListBranch(tbCode, offset, limit);
        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", cards);
        return resultVo;
    }

}
